﻿<UserControl x:Class="WpfAppHost.AddinsUserControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    <UserControl.Resources>
        <SolidColorBrush x:Key="ListBorder" Color="#828790"/>
        <Style x:Key="AddinListBoxStyle" TargetType="{x:Type ListBox}">
            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}"/>
            <Setter Property="BorderBrush" Value="{StaticResource ListBorder}"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
            <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
            <Setter Property="ScrollViewer.CanContentScroll" Value="true"/>
            <Setter Property="VerticalContentAlignment" Value="Center"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBox}">
                        <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="1">
                            <ScrollViewer Padding="{TemplateBinding Padding}" Focusable="false">
                                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </ScrollViewer>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                            </Trigger>
                            <Trigger Property="IsGrouping" Value="true">
                                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="VerticalAlignment" Value="Stretch"/>
            <Setter Property="ItemTemplate" Value="{DynamicResource AddinListBoxItemTemplate}"/>
        </Style>
        <DataTemplate x:Key="AddinListBoxItemTemplate">
            <Border BorderBrush="DodgerBlue" BorderThickness="2,2,2,2" Margin="2,2,2,2" Padding="5,5,5,5" CornerRadius="5,5,5,5" x:Name="border">
                <Border.Background>
                    <LinearGradientBrush>
                        <GradientStop Color="#FFFFFF"  Offset="0"/>
                        <GradientStop Color="#EEEEEE"  Offset="1"/>
                    </LinearGradientBrush>
                </Border.Background>
                <DockPanel x:Name="LayoutRoot" Width="Auto" Height="Auto" LastChildFill="True">
                    <Image DockPanel.Dock="Left" Width="64" Height="64" VerticalAlignment="Top" Source="{Binding AddinIconUri}" x:Name="AddinImage"/>
                    <StackPanel Width="Auto" Height="Auto" VerticalAlignment="Stretch" Margin="5,0,10,0">
                        <TextBlock FontWeight="Bold" Text="{Binding Path=Name}"/>
                        <WrapPanel Margin="10,0,0,0">
                            <TextBlock Text="{Binding Path=Author}"/>
                            <TextBlock Text=", Version: "/>
                            <TextBlock Text="{Binding Path=Version}"/>
                        </WrapPanel>
                        <TextBlock HorizontalAlignment="Left" Margin="10,0,0,0" Text="{Binding Path=Description}" Width="200" TextWrapping="Wrap" x:Name="AddinDescriptionText"/>

                        <WrapPanel Width="Auto" Height="Auto" VerticalAlignment="Bottom" HorizontalAlignment="Right" x:Name="wrapPanel">
                            <WrapPanel.Style>
                                <Style>
                                    <Style.Triggers>
                                        <DataTrigger Binding="{Binding Path=IsSelected,RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type ListBoxItem} } }" Value="False">
                                            <Setter Property="WrapPanel.Visibility" Value="Collapsed"/>
                                        </DataTrigger>
                                    </Style.Triggers>
                                </Style>
                            </WrapPanel.Style>
                            <Button Width="80" Height="22" Content="Remove" DockPanel.Dock="Right" Margin="2.5,0,2.5,0" x:Name="RemoveButton" Click="RemoveButton_Click" />
                        </WrapPanel>
                    </StackPanel>
                </DockPanel>
            </Border>
        </DataTemplate>
        <Style x:Key="AddinListBoxItemStyle" TargetType="{x:Type ListBoxItem}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="HorizontalContentAlignment" Value="{Binding Path=HorizontalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="VerticalContentAlignment" Value="{Binding Path=VerticalContentAlignment, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
            <Setter Property="Padding" Value="2,0,0,0"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type ListBoxItem}">
                        <Border x:Name="Bd" SnapsToDevicePixels="true" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="{TemplateBinding Padding}">
                            <ContentPresenter HorizontalAlignment="Stretch" VerticalAlignment="Stretch" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Border>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.HighlightBrushKey}}"/>
                                <!--Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.HighlightTextBrushKey}}"-->
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="IsSelected" Value="true"/>
                                    <Condition Property="Selector.IsSelectionActive" Value="false"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
                                <!--Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"-->
                            </MultiTrigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>

    <ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto">
        <DockPanel LastChildFill="True" MinWidth="200" MinHeight="200">
            <WrapPanel HorizontalAlignment="Center" DockPanel.Dock="Bottom">
                <Button x:Name="AddButton" Click="AddButton_Click">Install Addin From File</Button>
            </WrapPanel>
            <ListBox Name="listBoxInstalled" Style="{DynamicResource AddinListBoxStyle}" ItemContainerStyle="{DynamicResource AddinListBoxItemStyle}">
            </ListBox>
        </DockPanel>
    </ScrollViewer>
</UserControl>
